<template>
<j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top:50px"
    cancelText="关闭">

    <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="储位编码">
                <a-input placeholder="请输入储位编码" v-model="queryParam.locationCode"></a-input>
            </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="储位名称">
                <a-input placeholder="请输入储位名称" v-model="queryParam.locationName"></a-input>
            </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
            </a-col>
        </a-row>
        </a-form>
    </div>
    <!-- 查询区域-END -->
    <div>
        <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        :rowKey="(record) => record.id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange , type: checkval}"
        class="j-table-force-nowrap1"
        @change="handleTableChange"/>
    </div>
    </a-card>
</j-modal>
</template>

<script>
import Vue from 'vue'
import { AntDesignOutline, DashboardOutline, TwitterOutline, SearchOutline } from '@ant-design/icons'
import AntdIcon from '@ant-design/icons-vue'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import { getAction } from '@api/manage'
AntdIcon.add(AntDesignOutline, DashboardOutline, SearchOutline)
Vue.use(AntdIcon)
import ErpLocationList from '@/views/modules/location/ErpLocationList'

export default {
    name: 'StorageLocation',
    describes: '选择仓库储位',
    props: {
        modalWidth: {
            type: Number,
            required: false,
            default: 1200
        },
        checkval: {
            type: String,
            default: 'radio'
        },
        // 仓库编码
        warehouseCode: {
            type: String,
            default: ''
        },
        // 原本的储位-用于储位调整
        oldStorageLocation: {
            type: String,
            default: null
        },
    },
    mixins: [mixinDevice, JeecgListMixin],
    components: {
    ErpLocationList,
    },
    data() {
    return {
        visible: false,
        title: '选择储位',
        columns: [
        {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
            return parseInt(index)+1;
            }
        },
        {
            title:'储位编码',
            align:"center",
            dataIndex: 'locationCode'
        },
        {
            title:'储位名称',
            align:"center",
            dataIndex: 'locationName'
        },
        {
            title:'仓库编码',
            align:"center",
            dataIndex: 'warehouseCode'
        },
        {
            title:'仓库名称',
            align:"center",
            dataIndex: 'warehouseName'
        },
        ],
        url: {
        list: '/wms/basic/warehouse/getStorageLocationList',
        },
    }
    },
    created() {
    this.loadData(1);
    },
    mounted() {
    this.$nextTick(() => {
    })
    },
    computed: {},
    methods: {
    handleSubmit() {
        let selectedRow = null;
        selectedRow = this.selectionRows[0];
        //传递选中的数据
        this.$emit("handleOk", {data: selectedRow });
        this.searchReset(false)
        this.onClearSelected();
        this.close();
    },
    searchReset() {
        this.queryParam = {};
        this.loadData(1);
    },
    onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectionRows = selectionRows
    },
    add() {
        this.showModal()
    },
    showModal() {
        this.visible = true
        this.queryParam = {}
        this.loadData(1)
    },
    initDictConfig() {},
    handleCancel() {
        this.close()
    },
    handleOk() {
        this.$emit('handlerOk', this.selectionRows[0])
        this.close()
    },
    close() {
        this.queryParam = {}
        this.selectedRowKeys = []
        this.selectionRows = []
        this.visible = false
    },
    loadData(arg) {
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
        this.ipagination.current = 1;
        }
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        params.warehouseCode = this.warehouseCode;
        params.pageSize = '10';
        params.oldStorageLocation = this.oldStorageLocation;
        getAction(this.url.list, params).then((res) => {
        if (res.success) {
            this.dataSource = res.result.records || res.result;
            if (res.result.total) {
            this.ipagination.total = res.result.total;
            } else {
            this.ipagination.total = 0;
            }
        } else {
            this.$message.warning(res.message)
        }
        }).finally(() => {
        this.loading = false
        })
    },
  },
}
</script>

<style scoped>
/* 覆盖Dropdown菜单项在悬停时的背景颜色 */
.ant-dropdown-menu-item:hover,
.ant-dropdown-menu-submenu-title:hover {
    background-color: inherit; /* 或者设置为初始背景色 */
}
</style>